<template>
  <el-dialog
    v-el-drag-dialog
    title="出库单明细"
    :visible.sync="visible"
    width="900px"
  >
    <el-form ref="form" :model="form" :inline="true" label-width="100px">
      <el-form-item label="入库单号" prop="name">
        <el-input v-model="temp.stockCode" disabled />
      </el-form-item>
      <el-form-item label="操作人" prop="name">
        <el-input v-model="temp.operator" disabled />
      </el-form-item>

      <el-form-item label="操作时间" prop="name">
        <el-input v-model="createTime" disabled />
      </el-form-item>

      <el-form-item label="入库仓库" prop="name">
        <el-input v-model="temp.storeName" disabled />
      </el-form-item>

      <el-form-item label="配送车辆" prop="name">
        <el-input v-model="temp.carNumber" disabled />
      </el-form-item>

      <el-form-item label="审核时间" prop="name">
        <el-input v-model="enterDt" disabled />
      </el-form-item>

      <el-form-item label="备注" prop="name">
        <el-input v-model="temp.remark" disabled />
      </el-form-item>
    </el-form>

    <lb-table
      ref="lbTable"
      v-el-height-adaptive-table="{ bottomOffset: 10 }"
      border
      highlight-current-row
      element-loading-text="加载中"
      :column="tableData.column"
      :data="tableData.data"
      @fetch="fetchData"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { querystoreDetailList, selectOrgSNNoAndReType } from '@/api'
  import { formatColumnMap, parseTime } from '@/utils'
  export default {
    name: 'store-info',
    data() {
      return {
        visible: false,
        temp: {},
        form: {},
        storeMap: [],
        statusMap: [
          { value: 1, desc: '重', key: 'HEAVY' },
          { value: 2, desc: '轻', key: 'LIGHT' },
          { value: 3, desc: '回收', key: 'RECYCLE' },
          { value: 4, desc: '故障', key: 'BROKEN' },
          { value: 5, desc: '已损坏', key: 'CORRUPT' },
          { value: 6, desc: '正常', key: 'NORMAL' },
          { value: 7, desc: '报废', key: 'SCRAPPED' },
          { value: 8, desc: '过期', key: 'EXPIRED' },
          { value: 9, desc: '问题重瓶', key: 'QUEHEAVY' }
        ],
        operatorTypeMap: [
          { value: 0, desc: '无', key: 'DEFAULT' },
          { value: 1, desc: '调拨', key: 'DB' },
          { value: 2, desc: '充装', key: 'CZ' },
          { value: 3, desc: '送检', key: 'SJ' },
          { value: 4, desc: '暂存', key: 'ZC' },
          { value: 5, desc: '采购', key: 'CG' },
          { value: 6, desc: '托管', key: 'TG' },
          { value: 101, desc: '销售', key: 'XS' },
          { value: 102, desc: '押/退', key: 'ZL' },
          { value: 103, desc: '欠/还', key: 'QP' },
          { value: 104, desc: '回收/置换', key: 'HS' },
          { value: 105, desc: '退货', key: 'TH' },
          { value: 106, desc: '冲红', key: 'CH' }
        ],
        tableData: {
          column: [
            {
              type: 'index',
              align: 'center'
            },
            {
              prop: 'gtName',
              label: '商品类型'
            },
            {
              prop: 'goodsName',
              label: '商品名称'
            },
            {
              prop: 'goodsSpec',
              label: '规格型号'
            },
            {
              prop: 'unitName',
              label: '单位'
            },
            {
              prop: 'gdStatus',
              label: '状态',
              render: (h, scope) => (
                <div>
                <span>
                  {scope.row.gdStatus &&
                  formatColumnMap(
                    this.statusMap,
                    'value',
                    scope.row.gdStatus,
                    'desc'
                  )}
                </span>
                </div>
              )
            },

            {
              prop: 'operatorType',
              label: '类型',
              render: (h, scope) => (
                <div>
                <span>
                  {scope.row.operatorType &&
                  formatColumnMap(
                    this.operatorTypeMap,
                    'value',
                    scope.row.operatorType,
                    'desc'
                  )}
                </span>
                </div>
              )

            },
            {
              prop: 'gdCount',
              label: '出库数量'
            },
            {
              prop: 'gdCount',
              label: '净重'
            },

            {
              prop: 'remark',
              label: '备注',
              render: (h, scope) => {
                return (
                  <div>
                    {scope.row._edit ? (
                      <el-input
                        value={scope.row[scope.column.property]}
                        onInput={val => {
                          scope.row[scope.column.property] = val
                        }}
                      ></el-input>
                    ) : (
                      <span>{scope.row[scope.column.property]}</span>
                    )}
                  </div>
                )
              }
            }
          ],
          data: []
        }
      }
    },
    computed: {
      createTime: function() {
        return this.temp.createTime && parseTime(this.temp.createTime, '{y}-{m}-{d} {h}:{i}:{s}')
      },
      enterDt: function() {
        return this.temp.enterDt && parseTime(this.temp.enterDt, '{y}-{m}-{d} {h}:{i}:{s}')
      }
    },
    created() {
      this.initStoreMap()
    },
    methods: {
      open(temp) {
        this.temp = temp
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          // this.$nextTick(() => {
          //   this.$refs.lbTable.fetch({ currentPage: 1 })
          // })
        })
      },
      initStoreMap() {
        selectOrgSNNoAndReType({
          reType: 4
        }).then(res => {
          this.storeMap = res.data
        })
      },

      async fetchData() {
        console.log('ssss')
        const res = await querystoreDetailList({ // 入库单明细
          stockInCode: 'GdStatus'
        })
        console.log('res', res)
        // const storeId = this.form.storeId
        // querystoreDetailList({
        //   StockFullReType: '',
        //   GdStatus: ''
        // }).then(res => {
        //   this.tableData.data = res.data.rows
        // })
      }
    }
  }
</script>

<style lang="scss" scoped></style>
